#include "sw_background.h"

#include <allegro5\allegro.h>
#include <allegro5\allegro_image.h>
#include "globals.h"

sw_background::sw_background(char* filename) {
	bitmap = al_load_bitmap(filename);
	scrolling_factor = 0.7;
}

sw_background::~sw_background() {
	al_destroy_bitmap(bitmap);
}

void sw_background::draw_on_screen(float topleftx, float toplefty) {
for(int i=0; i<10; i++) {
	int width = al_get_bitmap_width(bitmap);
	int height = al_get_bitmap_height(bitmap);
	int thex = - topleftx*scrolling_factor/global_pixel_width;
	while (thex<0) thex += width;
	thex = thex % global_screen_width;
	thex -= width;
	int they = -toplefty*scrolling_factor/global_pixel_height;
	while (they<0) they += height;
	they = they % global_screen_height;
	they -= height;

	int beginy = they;
	while(thex <= global_screen_width) {
		while (they <= global_screen_height) {
			al_draw_bitmap(bitmap, thex, they, 0);
			they += height;
		}
		they = beginy;
		thex += width;
	}
}
}